package beans;

import java.util.Date;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import model.User;

import dao.ServerLogEntryDao;
import dao.UserDao;
import enumerations.LogType;

/**
 * Session Bean implementation class ServerLogEntryBean
 * insert, on serverLogEntry
 * 
 * @author zahariem
 */
@Stateless
public class ServerLogEntryBean implements ServerLogEntryBeanRemote {

	@EJB
	ServerLogEntryDao sleDao;
	
	@EJB
	UserDao userDao;

    /**
     * Default constructor. 
     */
    public ServerLogEntryBean() {
        // TODO Auto-generated constructor stub
    }
    
    /**
     * Insereaza op in serverlogentry table
     * 
     * @author zahariem
     * 
     * @param type
     * @param content
     * @param date
     * @param author autorul operatiei 
     */
    public void insertOpToLog(String type, String content, Date date, int author){
    	
    	LogType typeReceived = null;
		for (LogType logtype : LogType.values()) {
			if (logtype.toString().equals(type)) {
				typeReceived = logtype;
			}
		}
		User auth=userDao.getUserById(author);
		sleDao.insertOpToLog(typeReceived, content, date, auth);
    }
}
